package com.arcbbs.service.impl;

import com.arcbbs.entity.FormBoard;
import com.arcbbs.mapper.FormBoardMapper;
import com.arcbbs.result.PageResult;
import com.arcbbs.service.FormBoardService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class FormBoardServiceImpl implements FormBoardService {
    @Resource
    private FormBoardMapper formBoardMapper;
    public List<FormBoard> getboardtree(Integer postType){

       List<FormBoard> list1=formBoardMapper.selectall();

        return convertLinetoTree(list1,0);
    }
    private List<FormBoard> convertLinetoTree(List<FormBoard> dataList,Integer pid){
        List<FormBoard> children=new ArrayList<>();
        for (FormBoard formBoard:dataList){

            if(formBoard.getPBoardId().equals(pid)){

                formBoard.setChildren(convertLinetoTree(dataList,formBoard.getBoardId()));
                children.add(formBoard);
            }
        }

        return children;
    }
    public PageResult selectbypage(Integer pageNo){
        PageHelper.startPage(pageNo,10);
        Page<FormBoard> page=formBoardMapper.page();
        List<FormBoard> list=page.getResult();
        long total=page.getTotal();
        return new PageResult(total,list);
    }

}
